|
|
|
|
|
|
|
supply the input box's message (prompt) and, optionally, a title and default value. An example of the InputBox function is the following: |
|
|
|
|
|
|
|
|
Dim sMsg as String, sUserName As String
sMsg = "Please type your name below:"
sUserName = InputBox(sMsg, "Enter user name", "Anonymous") |
|
|
|
|
|
|
|
|
In this statement, the information returned by the InputBox function is stored in the variable sUserName. The first argument, the prompt parameter, represents the message that is displayed to the user to indicate what should be entered in the box. Like the message in the message box, the prompt can display up to approximately 1,024 characters before it is truncated. Word-wrapping is automatically performed on the text in the prompt so that it fits inside the box. Also, as with the message box, you can insert a carriage return/line feed combination (vbCrLf) to force the prompt to show multiple lines or to separate lines for emphasis. |
|
|
|
|
|
|
|
|
After the prompt comes the title argument, which specifies the text in the input box's title bar. The other argument in the preceding example is the default argument. If included, it appears as an initial value in the input box. The user can accept this value, modify it, or erase it and enter a completely new value. |
|
|
|
|
|
|
|
|
The minimum requirement for the InputBox function is a prompt parameter, as in this statement: |
|
|
|
|
|
|
|
|
sReturnVal = InputBox("How's the weather?") |
|
|
|
|
|
|
|
|
In addition to the input box's optional parameters to specify a window title and default value, other optional parameters allow you to set its initial screen position, as well as the help file to be used if the user needs assistance. Refer to the complete syntax of the InputBox function in Visual Basic's help system. |
|
|
|
|
|
|
|
|
|
Unlike the MsgBox function, no option in the InputBox function specifies any command buttons other than the defaults of OK and Cancel.  |
|
|
|
|
|
|
|
|
|
|
Values Returned by InputBox |
|
|
|
|
|
|
|
|
When the input box is used, the user can enter up to 255 characters of text in the input box's entry area, which resembles a text box. If the user types more text than will fit in the displayed entry area, the text he or she has already typed scrolls to the left. After the user is done, he or she can choose the OK or Cancel button. If the user chooses the OK button, the input box returns whatever is in the text box, whether it is new text or the default text. If the user chooses the Cancel button, the input box returns an empty string, regardless of what is in the text box. |
|
|
|
|
|
|
|
|
To be able to use the information entered by the user, you must determine if the data meets your needs. First, you probably should make sure that the user actually entered some information and chose the OK button. You can do so by using the Len function to determine the length of the returned string. If the length is zero, the user clicked the Cancel button or left the input field blank. If the length of the string is greater than zero, you know that the user entered |
|
|
|
|
|